Skip to content

fix(usvg): inherit gradientTransform and patternTransform via href - #1135

Merged
LaurenzV merged 2 commits into
linebender:mainfrom
killerdevildog:fix-inherit-paint-server-transform-via-href
Oct 3, 2026
Merged

LaurenzV merged 2 commits into
linebender:mainfrom
killerdevildog:fix-inherit-paint-server-transform-via-href

Conversation

@killerdevildog

Copy link
Copy Markdown
Contributor

Fixes #1134.

A gradient or pattern that references another one through href did not inherit its gradientTransform or patternTransform. For example, <linearGradient id="lg2" xlink:href="#lg1"/>, where lg1 has gradientTransform="rotate(90 0.5 0.5)", rendered left to right instead of top to bottom.

This regressed in 9101f30 (first released in v0.37.0), which replaced resolve_attr(node, AId::GradientTransform).attribute(..) with node.resolve_transform(..) to support transform-origin. resolve_transform only reads the element itself, so the href lookup was lost and the GradientTransform entries in resolve_lg_attr and resolve_rg_attr became unused. Resolving the defining element with resolve_attr first restores inheritance and keeps transform-origin support. A transform set on the element itself still takes precedence. When the transform is inherited, transform-origin is read from the same element that defines the transform.

Before After
Before: resvg main renders the gradient left to right After: resvg with the fix renders the gradient top to bottom

This PR changes only crates/usvg/src/parser/paint_server.rs.

Validation: the reproducer from #1134 fails before the change and passes afterward; resvg's output now matches rsvg-convert 2.58 to within 1/255 per color channel (before the change it differed by up to 255). Local paired cases covering linear, radial and pattern templates, a radial gradient using a linear template, a two-level href chain, and an element that overrides the inherited transform each render pixel-identically to the same transform set directly on the element. cargo test --release -p resvg -p usvg passes (1731 integration tests, no reference image changes) and cargo fmt --check is clean. The local regression tests are not included in this PR. Tested on Linux only.

@luisbg

luisbg commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Fix looks good to me but we should have a test added to avoid this issue regressing in the future.

killerdevildog and others added 2 commits October 3, 2026 08:35
A gradient or pattern that references another one through `href`/`xlink:href` did not inherit its `gradientTransform` or `patternTransform`. Stops, coordinates, units and `spreadMethod` were inherited, but the transform was silently dropped. For example, `<linearGradient id="lg2" xlink:href="#lg1"/>`, where `lg1` has `gradientTransform="rotate(90 0.5 0.5)"`, rendered left-to-right instead of top-to-bottom, and a referencing pattern lost its rotation.

This is a regression from 9101f30 ("Add support for the `transform-origin` attribute"), which replaced `resolve_attr(node, AId::GradientTransform).attribute(..)` with `node.resolve_transform(..)`. `resolve_transform` only reads the attribute from the element itself, so the `GradientTransform` entries in `resolve_lg_attr` and `resolve_rg_attr` became unused.

SVG 2 lists `gradientTransform` among the attributes copied from a template `linearGradient` or `radialGradient`, and `patternTransform` among those copied from a template `pattern` (https://www.w3.org/TR/SVG2/pservers.html). SVG 1.1 likewise states that attributes defined on the referenced element but not on this element are inherited.

Resolve the element that defines the transform with `resolve_attr` before calling `resolve_transform`, in `convert_linear`, `convert_radial` and `convert_pattern`. A transform set on the element itself still takes precedence over the referenced one.

Signed-off-by: killerdevildog <quaylynrimer11@gmail.com>
Signed-off-by: killerdevildog <software.quaylynrimer@gmail.com>
@LaurenzV
LaurenzV force-pushed the fix-inherit-paint-server-transform-via-href branch from d70feeb to 268a26d Compare October 3, 2026 06:49
@LaurenzV

LaurenzV commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@LaurenzV
LaurenzV merged commit 1fe3cfe into linebender:main Oct 3, 2026
10 checks passed
dmtrKovalenko pushed a commit to dmtrKovalenko/svgr that referenced this pull request Oct 13, 2026
…ref` (linebender#1135)

Upstream: linebender/resvg@1fe3cfe

Applied as-is (paths mapped to crates/usvgr and crates/svgr/tests). No new
tree fields, so no cache/hash or svgtree proc-macro impact.

(cherry picked from commit 1fe3cfe)
HiroyukiFuruno added a commit to HiroyukiFuruno/katana-resvg that referenced this pull request Oct 25, 2026
* Update Windows release runner to `windows-latest` (linebender#1113)

* c-api: add missing SVGZ error enum (linebender#1122)

Add the missing `RESVG_ERROR_SVGZ_UNSUPPORTED` enum value to `resvg.h`
so the C API enum values remain in sync with the Rust definition and
subsequent error codes are not shifted.

While we're here, simplify this enum description (as the `svgz` feature
is enabled by default) and add the corresponding Qt error string in
`ResvgQt.h`.

Fixes: linebender#1112.

---

Verified against wasm-vips with this sed substitution:

https://github.com/kleisauke/wasm-vips/blob/8f38cbbb70d7536bd0f3d70e308c501cbe4f2e22/build.sh#L442-L443

* Add regression test for `fr` resolution in referenced radial gradients (linebender#1123)

As requested in linebender#1098

* fix(usvg): use the viewport as the bbox of a sliced <image> (linebender#1077)

* Add aarch64 release artifacts for Linux and Windows (linebender#1132)

Adds native aarch64 builds to the release workflow.

- **Linux aarch64** on the `ubuntu-24.04-arm` runner →
`resvg-linux-aarch64.tar.gz`, `usvg-linux-aarch64.tar.gz`
- **Windows aarch64** on the `windows-11-arm` runner →
`resvg-win-aarch64.zip`, `usvg-win-aarch64.zip`

Updates the workflow's actions, two of which still declared the
end-of-life node12 runtime:

- `alexellis/upload-assets` 0.2.2 → 0.5.0 (node12 → node24)
- `battila7/get-version-action` removed — unmaintained since 2021 and
node12; the workflow only triggers on `v*` tags, so the version is just
`${GITHUB_REF_NAME#v}`
- `actions/checkout` v2 → v7, `softprops/action-gh-release` v2 → v3

Renames the existing job to explicitly say `x86_64` and differentiate
`aarch64`

Closes linebender#968

* Convert CI release job to use a Matrix (linebender#1133)

Some CI cleanup suggested by LLM review of
linebender#1132. Has been verified as
working on my fork.

## Changes made

- Collapse the six per-platform release-* jobs into one release-binaries
matrix job over {linux, win, macos} × {x86_64, aarch64}. Asset names are
derived from the matrix (`resvg-$SUFFIX.{tar.gz,zip}`). This renamea
`resvg-win64.zip` / `usvg-win64.zip` to `resvg-win-x86_64.zip` /
`usvg-win-x86_64.zip` to match the linux-* / macos-* / win-aarch64
naming. This is a breaking change for anyone scripting downloads of the
old names.
- Drop the crates/c-api release builds (and the ilammy/msvc-dev-cmd
step): their output was never collected or uploaded, so they only cost
CI time.
- Split the vendored sources archive and the Windows Explorer
thumbnailer into their own jobs
- Upload assets with `softprops/action-gh-release@v3` files: (already
used to create the release) instead of the third-party
`alexellis/upload-assets`.

* tests: load test fonts in a deterministic order (linebender#1136)

`fontdb::load_fonts_dir` walks the directory with `std::fs::read_dir`,
which outputs entries in filesystem order. That order is not stable
across machines, and the test harness depends on it.

Replace `load_fonts_dir` with an explicit sorted list so order is
identical everywhere. The whole suite passes unchanged, so no stored
reference image depended on the previous ordering.

* fix(usvg): inherit `gradientTransform` and `patternTransform` via `href` (linebender#1135)

* Inherit `dominant-baseline` into nested `<tspan>` elements (linebender#1086)

* Fix bug in filter chains with different filter regions (linebender#1144)

* Add support for `plus-lighter` and `lighter` (linebender#1142)

* Apply root SVG transform after the `viewBox` mapping (linebender#1085)

* Add `--query-bbox` to CLI (linebender#1050)

* Support floating point viewbox in resvg binary (linebender#875)

* Fix `feMorphology` kernel size and radius rounding (linebender#1120)

* Bug fixes for RTL text and `dx`/`dy` (linebender#1145)

* Fix font fallback logging and avoid repeated lookups (linebender#1154)

* Fix rendering of filters with skews and rotations (linebender#1155)

* Fix marker viewport clipping with preserveAspectRatio (linebender#1163)

* Resolve paint servers in masks, patterns and `feImage` before caching (linebender#1164)

* Optimize clipped layers (linebender#1158)

* Remove reference to nonexistent check.py from tests README (linebender#1181)

* Install ResvgQt.h with cargo-c (linebender#1182)

* Prepare v0.49.0 release (linebender#1183)

* fix: Windowsサムネイルの依存版を0.49へ揃える Refs #1

---------

Co-authored-by: TheBestWebsite <164817940+TheBestWebsite@users.noreply.github.com>
Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
Co-authored-by: Tim Voßhenrich <94936637+T1mVo@users.noreply.github.com>
Co-authored-by: Stefano <stefano.d@posteo.de>
Co-authored-by: Chongyi Zheng <git@zcy.dev>
Co-authored-by: Nico Burns <nico@nicoburns.com>
Co-authored-by: Luis de Bethencourt <luis@debethencourt.com>
Co-authored-by: Quaylyn Rimer <31830590+killerdevildog@users.noreply.github.com>
Co-authored-by: Teo Mal <76534902+teolines@users.noreply.github.com>
Co-authored-by: Matt Hargett <plaztiksyke@gmail.com>
Co-authored-by: Simon Ser <contact@emersion.fr>
Co-authored-by: Jeremy James <jeremy.james@gmail.com>
Co-authored-by: WaterWhisperer <waterwhisperer24@qq.com>
Co-authored-by: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com>
Co-authored-by: Cees-Kettenis <101450983+Cees-Kettenis@users.noreply.github.com>
Co-authored-by: Rodrigue Villetard <rodrigue@gassagosso.coop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gradientTransform and patternTransform are not inherited through href

3 participants